package com.jeasonzhao.model.hibernate;

import java.lang.reflect.Field;

import com.jeasonzhao.commons.utils.DataTypes;

public class HBFieldMappedBean
{
    private Field field = null;
    private Class dataType = null;
    private String fieldName = null;
    private String columnName = null;
    private boolean enumType = false;
    private boolean usingEnumName = false;
    private boolean primaryKey = false;
    private boolean notNull = false;
    private boolean unique = false;
    private String descName = null;
    public HBFieldMappedBean()
    {
        super();
    }

    public String getColumnName()
    {
        return columnName;
    }

    public Class getDataType()
    {
        return dataType;
    }

    public Field getField()
    {
        return field;
    }

    public boolean isNotNull()
    {
        return notNull;
    }

    public boolean isPrimaryKey()
    {
        return primaryKey;
    }

    public boolean isUnique()
    {
        return unique;
    }

    public boolean isUsingEnumName()
    {
        return usingEnumName;
    }

    public boolean isEnumType()
    {
        return enumType;
    }

    public String getDescName()
    {
        return descName;
    }

    public String getFieldName()
    {
        return fieldName;
    }

    public void setColumnName(String columnName)
    {
        this.columnName = columnName;
    }

    public void setDataType(Class dataType)
    {
        this.dataType = dataType;
    }

    public void setDescName(String descName)
    {
        this.descName = descName;
    }

    public void setEnumType(boolean enumType)
    {
        this.enumType = enumType;
    }

    public void setField(Field field)
    {
        this.field = field;
    }

    public void setFieldName(String fieldName)
    {
        this.fieldName = fieldName;
    }

    public void setNotNull(boolean notNull)
    {
        this.notNull = notNull;
    }

    public void setPrimaryKey(boolean primaryKey)
    {
        this.primaryKey = primaryKey;
    }

    public void setUnique(boolean unique)
    {
        this.unique = unique;
    }

    public void setUsingEnumName(boolean usingEnumName)
    {
        this.usingEnumName = usingEnumName;
    }

    public Object getValue(Object obj)
        throws IllegalAccessException,IllegalArgumentException
    {
        if(null == obj)
        {
            return null;
        }
        this.getField().setAccessible(true);
        return this.getField().get(obj);
    }

    public void setValue(Object obj,Object v)
        throws IllegalAccessException,IllegalArgumentException
    {
        if(null == obj)
        {
            return;
        }
        DataTypes datatype = DataTypes.fromClass(this.getDataType());
        this.getField().setAccessible(true);
        this.getField().set(obj,datatype.castValue(v));
    }

}
